package com.eastfair.venuebooking.dao;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.eastfair.boot.mapper.SuperMapper;
import com.eastfair.venuebooking.entity.ContractManage;
import com.eastfair.venuebooking.vo.ContractHistogramVO;
import com.eastfair.venuebooking.vo.ContractManageVO;
import com.eastfair.venuebooking.vo.SpaceLeaseStatisticsVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.math.BigDecimal;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * Mapper 接口
 * 合同
 * </p>
 *
 * @author lyw
 * @date 2022-06-20
 */
@Repository
public interface ContractManageMapper extends SuperMapper<ContractManage> {

    /**
     * 查询合同列表.
     *
     * @param pageParams   the page params
     * @param queryWrapper the query wrapper
     * @return the page
     */
    IPage<ContractManageVO> listContractManageVOs(IPage<ContractManage> pageParams,
                                                  @Param(Constants.WRAPPER) QueryWrapper<ContractManage> queryWrapper);


    List<SpaceLeaseStatisticsVO> getContractManageList();

    /**
     * 通过客户ID统计合同总金额.
     *
     * @param customerId the customer id
     * @return the long
     */
    @Select("SELECT SUM( IF ( contract_amount IS NULL, 0, contract_amount ) )  FROM vb_contract_manage WHERE is_deleted = 0 AND cutomer_id = #{customerId}")
    BigDecimal countContractAmountByCustomerId(@Param("customerId") Long customerId);

    /**
     * 通过客户ID统计合同预定的计价面积.
     *
     * @param customerId the customer id
     * @return the long
     */
    Double countPriceAreaByCustomerId(@Param("customerId") Long customerId);

    /**
     * 通过客户ID统计合同预定场馆数量.
     *
     * @param customerId the customr id
     * @return the long
     */
    long countSpaceByCustomerId(@Param("customerId") Long customerId);

    /**
     * 客户ID查询每年的成交量.
     *
     * @param id the id
     * @return the map
     */
    List<ContractHistogramVO> countEveryYearContractAmountByCustomerId(@Param("customerId") Long id);
}
